package com.cskaoyan.wx.controller;

import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.wx.bean.vo.GoodsListVo;
import com.cskaoyan.wx.bean.vo.WxGoodsCategoryVo;
import com.cskaoyan.wx.bean.vo.WxGoodsCountVo;
import com.cskaoyan.wx.bean.vo.WxGoodsListVo;
import com.cskaoyan.wx.bean.vo.goodsdetail.WxGoodsDetailVo;
import com.cskaoyan.wx.service.WxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WxGoodsController {

    @Autowired
    WxGoodsService wxGoodsService;

    /**
     * 作者：grz
     * 功能：统计当前商品数量
     */
    @RequestMapping("wx/goods/count")
    public BaseRespVo count() {

        WxGoodsCountVo wxGoodsCountVo = new WxGoodsCountVo();
        wxGoodsCountVo.setGoodsCount(wxGoodsService.goodsCount());
        return BaseRespVo.ok(wxGoodsCountVo);
    }


    /**
     * 作者：grz
     * 功能：查询类目
     *
     * @param id 类目的id
     * @return BaseRespVo WxGoodsCategoryVo
     */
    @RequestMapping("wx/goods/category")
    public BaseRespVo current(Integer id) {

        WxGoodsCategoryVo wxGoodsCategoryVo = wxGoodsService.currentCategory(id);

        return BaseRespVo.ok(wxGoodsCategoryVo);

    }


    /**
     * 作者：grz
     * 功能：查询商品列表
     *
     * @param categoryId 类目的id
     * @param page       页数
     * @param size       每页的商品数量
     * @return BaseRespVo WxGoodsCategoryVo
     */
    @RequestMapping("wx/goods/list")
    public BaseRespVo list(Integer categoryId, Integer page, Integer size, String keyword, String sort, String desc) {

        WxGoodsListVo goodsListVo = wxGoodsService.list(categoryId, page, size, keyword, sort,  desc);

        return BaseRespVo.ok(goodsListVo);

    }

    /**
     * 作者：grz
     * 功能：商品详细信息
     *
     * @param id 商品id
     * @return BaseRespVo WxGoodsDetailVo
     */
    @RequestMapping("wx/goods/detail")
    public BaseRespVo detail(Integer id) {

        WxGoodsDetailVo wxGoodsDetailVo = wxGoodsService.detail(id);

        return BaseRespVo.ok(wxGoodsDetailVo);
    }


    /**
     * 作者：grz
     * 功能：商品推荐
     *
     * @param id 商品id
     * @return BaseRespVo GoodsListVo
     */
    @RequestMapping("wx/goods/related")
    public BaseRespVo related(Integer id) {

        GoodsListVo goodsListVo = wxGoodsService.related(id);

        return BaseRespVo.ok(goodsListVo);
    }

}
